package cn.com.idmy.cloud;

import cn.com.idmy.base.util.MaskUtil;
import cn.com.idmy.cloud.mask.Masks;
import com.alibaba.fastjson2.filter.ValueFilter;

public class GlobalValueFilter implements ValueFilter {
    @Override
    public Object apply(Object object, String name, Object value) {
        if (value instanceof String) {
            var maskConfigs = Masks.maskConfig();
            if (maskConfigs != null && maskConfigs.containsKey(name)) {
                var maskType = maskConfigs.get(name);
                return MaskUtil.mask((String) value, maskType.getLeft(), maskType.getRight());
            }
        }
        return value;
    }
}